package blackitheima2.ClassTest;

import blackitheima2.Domain.Student;

import java.lang.reflect.Field;

public class MyClass1 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException, InstantiationException {
        //创建Class类
        Class<?> aClass = Class.forName("blackitheima2.Domain.Student");
        //调用成员变量
        Field name = aClass.getDeclaredField("name");

        //暴力反射一下
        name.setAccessible(true);
        //创建对象
        Student stu = (Student) aClass.newInstance();

        //为成员变量赋值
        name.set(stu,"庄三");
        //获取值
        Object o = name.get(stu);
        System.out.println(o);
    }
}
